<?php
$viewChanges = @$_GET['viewChanges'];
if(isset ($_GET['RefTable'])){
$RefTable = @$_GET['RefTable'];
    
} else {
$RefTable = "All";
}
$lower = @$_GET['lower'];

if(!strlen($lower)>0) {
    $lower = 0;
}

if(strlen(trim($viewChanges))==0) {
    $viewChanges = " ";
}


echo '<div id="page_header">'."\n";
echo '<ul>'."\n";
echo '<li class="titlename2">View Logs ('.$RefTable.')</li>'."\n";
echo '</ul>'."\n";
echo '</div>'."\n";

echo '<div id="details-section">'."\n";
echo '<div id="RefDataDetailsC1">'."\n";

$base_page_name='index.php?view=Logs';

echo '<ul class="RefDataOverview">'."\n";

echo '<li class="colw33pc">'."\n";
echo '<a href="'.$base_page_name.'&amp;RefTable=all" >'."\n";
echo "Changes to All"."\n";
echo '</a>'."\n";
echo '</li>'."\n";

echo '<li class="colw33pc">'."\n";
echo '<a href="'.$base_page_name.'&amp;RefTable='.$PACTS_cfg->individualtablename.'" >'."\n";
echo "Changes to Individuals"."\n";
echo '</a>'."\n";
echo '</li>'."\n";

echo '<li class="colw33pc">'."\n";
echo '<a href="'.$base_page_name.'&amp;RefTable='.$PACTS_cfg->familytablename.'" >'."\n";
echo "Changes to Families"."\n";
echo '</a>'."\n";
echo '</li>'."\n";

echo '</ul>'."\n";
echo '<ul class="RefDataOverview">'."\n";

echo '<li class="colw33pc">'."\n";
echo '<a href="'.$base_page_name.'&amp;RefTable='.$PACTS_cfg->userstablename.'" >'."\n";
echo "Changes to Users"."\n";
echo '</a>'."\n";
echo '</li>'."\n";

echo '</ul>'."\n";
echo '</div>'."\n";
echo '</div>'."\n";




/*
 *
 *
?>
<p>
<a href="index.php?view=Logs&amp;viewChanges=all">Changes to All</a><br />
<a href="index.php?view=Logs&amp;viewChanges=Individual">Changes to Individual</a><br />
<a href="index.php?view=Logs&amp;viewChanges=Family">Changes to Family</a><br />
<a href="index.php?view=Logs&amp;viewChanges=users">Changes to Users</a><br />
<p>

<?php
*/




if(strlen($RefTable)>0) {
    // set defaults for phpMyEdit class

    $opts['RefTable'] = $RefTable;

    $opts['hn'] = $PACTS_cfg->dbserver;// user name
    $opts['un'] = $PACTS_cfg->dbuser;// user name
    $opts['pw'] = $PACTS_cfg->dbpass;//password
    $opts['db'] = $PACTS_cfg->dbname;//database
    $opts['tb'] = 'AuditTrail';
    $opts['url']['images'] = 'furniture/design/phpMyEditimages/';
    $opts['page_name'] = $base_page_name.'&RefTable='.$RefTable;

    // Options you wish to give the users
    // A - add,  C - change, P - copy, V - view, D - delete,
    // F - filter, I - initial sort suppressed
    $opts['options'] = 'PVF';
    // Navigation style: B - buttons (default), T - text links, G - graphic links
    // Buttons position: U - up, D - down (default)
    $opts['navigation'] = 'U';
    // Display special page elements
    $opts['display'] = array(
    'form'  => true,
    'query' => true,
    'sort'  => true,
    'time'  => false,
    'tabs'  => true
    );
    // Set default prefixes for variables
    $opts['js']['prefix']               = 'PME_js_';
    $opts['dhtml']['prefix']            = 'PME_dhtml_';
    $opts['cgi']['prefix']['operation'] = 'PME_op_';
    $opts['cgi']['prefix']['sys']       = 'PME_sys_';
    $opts['cgi']['prefix']['data']      = 'PME_data_';

/* Get the user's default language and use it if possible or you can
   specify particular one you want to use. Refer to official documentation
   for list of available languages. */
    $opts['language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'] . '-UTF8';
    // Number of records to display on the screen
    // Value of -1 lists all records in a table
    $opts['inc'] = 15;


    // Number of lines to display on multiple selection filters
    $opts['multiple'] = '4';


    // Name of field which is the unique key
    $opts['key'] = 'AuditTrailId';

    // Type of key field (int/real/string/date etc.)
    $opts['key_type'] = 'int';
    // Sorting field(s)
    $opts['sort_field'] = array('-AuditTMS');


    switch (strtolower($RefTable)) {
        case  "all" :
            break;
        case  "family" :
        $opts['filters'] = "ChangeTableName = '".$PACTS_cfg->familytablename."'";
            break;
        case  "individual" :
        $opts['filters'] = "ChangeTableName = '".$PACTS_cfg->individualtablename."'";
            break;
        case  "users" :
        $opts['filters'] = "ChangeTableName = '".$PACTS_cfg->userstablename."'";
            break;

        }
/*
$opts['filters'] = "column1 like '%11%' AND column2<17";
$opts['filters'] = "section_id = 9";
$opts['filters'] = "PMEtable0.sessions_count > 200";
*/

        $opts['fdd']['AuditTrailId'] = array(
  'name'     => 'AuditTrailId',
  'select'   => 'T',
  'options'  => 'AVCPDR', // auto increment
  'maxlen'   => 11,
  'default'  => '0',
  'sort'     => false
        );
        $opts['fdd']['AuditUserId'] = array(
  'name'     => 'AuditUserId',
  'select'   => 'T',
  'maxlen'   => 20,
  'sort'     => true
        );
        $opts['fdd']['AuditTMS'] = array(
  'name'     => 'AuditTMS',
  'select'   => 'T',
  'maxlen'   => 19,
  'default'  => 'CURRENT_TIMESTAMP',
  'sort'     => true
        );
        $opts['fdd']['ChangeTableName'] = array(
  'name'     => 'ChangeTableName',
  'select'   => 'T',
  'maxlen'   => 50,
  'sort'     => true
        );
        $opts['fdd']['ChangeType'] = array(
  'name'     => 'ChangeType',
  'select'   => 'T',
  'maxlen'   => 50,
  'sort'     => true
        );
        $opts['fdd']['OldData'] = array(
  'name'     => 'OldData',
  'select'   => 'T',
  'maxlen'   => 65535,
  'textarea' => array(
    'rows' => 5,
    'cols' => 50),
  'sort'     => false
        );
        $opts['fdd']['NewData'] = array(
  'name'     => 'NewData',
  'select'   => 'T',
  'maxlen'   => 65535,
  'textarea' => array(
    'rows' => 5,
    'cols' => 50),
  'sort'     => false
        );
        $opts['fdd']['FieldName'] = array(
  'name'     => 'FieldName',
  'select'   => 'T',
  'maxlen'   => 100,
  'sort'     => true
        );
        $opts['fdd']['PageName'] = array(
  'name'     => 'PageName',
  'select'   => 'T',
  'options'  => 'AVCPDR', // updated automatically (MySQL feature)
  'maxlen'   => 50,
  'sort'     => true
        );
        $opts['fdd']['RecordId'] = array(
  'name'     => 'RecordId',
  'select'   => 'T',
  'options'  => 'AVCPDR', // updated automatically (MySQL feature)
  'maxlen'   => 50,
  'sort'     => false
        );



        echo '<div class="phpMyEdit-sectionx">'."\n";
//        echo '<p class="titlename1">Audit Trail</p>'."\n";
        // now build the reference table

        // Now important call to phpMyEdit
        //require_once 'phpMyEdit.class.php';
        echo '<p class="titlename1">&nbsp;</p>'."\n";
        new phpMyEdit($opts);


        echo '</div>'."\n";

    }// end if any content










/*
if(@$_GET['viewChanges']) {


    if(strtolower($viewChanges)=="all") {
        echo "<b>Audit trail for All data</b><p>";
        $sqlWildCard = '%';
    } else {
        echo "<b>Audit trail for $viewChanges data</b><p>";

        if(strtolower($viewChanges)=="individual") {
            $sqlWildCard = $PACTS_cfg->individualtablename;
        }
        if(strtolower($viewChanges)=="family") {
            $sqlWildCard = $PACTS_cfg->familytablename;
        }
        if(strtolower($viewChanges)=="users") {
            $sqlWildCard = $PACTS_cfg->userstablename;
        }
    }
        //	echo "SELECT * FROM AuditTrail WHERE ChangeTableName Like '$viewChanges' ORDER BY `AuditTrailId` DESC   <p>";

        $sql = "SELECT * FROM AuditTrail WHERE ChangeTableName Like '".$sqlWildCard."' ORDER BY `AuditTrailId` DESC LIMIT $lower, $PACTS_cfg->getNumAuditRecords";

        $result = mysql_query("SELECT Count(*) as COUNT FROM AuditTrail WHERE ChangeTableName Like '".$sqlWildCard."' ORDER BY `AuditTrailId` DESC ",$PACTS_cfg->dblink);
        $row = mysql_fetch_array($result);
        $COUNT = $row["COUNT"];

        echo "Found ".$COUNT." entries<p>";
        //echo "$sql<p>";

        echo "<table><tr><td>";

        if($lower != 0) {
            echo ' <a href="index.php?view=Logs&amp;lower=0&viewChanges='.$viewChanges.'" ><b>First</b></a> '."\n";
        } else {
            echo " First ";
        }
        echo "</td><td>";
        if($lower > 0) {
            echo ' <a href="index.php?view=Logs&amp;lower='.($lower-$PACTS_cfg->getNumAuditRecords).'&amp;viewChanges='.$viewChanges.'" ><b>Previous</b></a> '."\n";
        } else {
            echo " Previous ";
        }
        echo "</td><td>";

        if($lower+$PACTS_cfg->getNumAuditRecords < $COUNT-1) {
            echo ' <a href="index.php?view=Logs&amp;lower='.($lower+$PACTS_cfg->getNumAuditRecords).'&amp;viewChanges='.$viewChanges.'" ><b>Next</b></a> '."\n";
        } else {
            echo " <font class=\"\">Next</font> ";
        }
        echo "</td><td>";

        if(!($lower+$PACTS_cfg->getNumAuditRecords >= $COUNT-1)) {
            echo ' <a href="index.php?view=Logs&amp;lower='.($COUNT-$PACTS_cfg->getNumAuditRecords).'&amp;viewChanges='.$viewChanges.'" ><b>Last</b></a> '."\n";
        } else {
            echo " Last ";
        }

        echo "</td></tr></table>";


        echo $PACTS_cfg->getHTMLtable($sql,TRUE);
        //exit;

    }// end if any content
 * */



    ?>